﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Bainx.WPF.Extend.Control
{
	/// <summary>
	/// WebBrowserCtrlPanel.xaml 的交互逻辑
	/// </summary>
	public partial class WebBrowserCtrlPanel : UserControl
	{
        /// <summary>
        /// 浏览器控制面板
        /// </summary>
		public WebBrowserCtrlPanel()
		{
			this.InitializeComponent();
            this.GoHomePage.Click += new RoutedEventHandler(GoHomePage_Click);
            this.GoNextPage.Click += new RoutedEventHandler(GoNextPage_Click);
            this.GoPreviousPage.Click += new RoutedEventHandler(GoPreviousPage_Click);
            this.Refresh.Click += new RoutedEventHandler(Refresh_Click);
            this.Loaded += new RoutedEventHandler(WebBrowserCtrlPanel_Loaded);
		}

        void WebBrowserCtrlPanel_Loaded(object sender, RoutedEventArgs e)
        {
            this.GoPreviousPage.IsEnabled = false;
            this.GoNextPage.IsEnabled = false;
        }
        /// <summary>
        /// 浏览器控制面板
        /// </summary>
        /// <param name="webBrowser"></param>
        public WebBrowserCtrlPanel(WebBrowserUserControl webBrowser)
            :this()
        {
            this.BindingWebBrowser = webBrowser;
        }

        void Refresh_Click(object sender, RoutedEventArgs e)
        {
             bindingWebBrowser.Refresh();
        }

        void GoPreviousPage_Click(object sender, RoutedEventArgs e)
        {
            bindingWebBrowser.GoBack();
        }

        void GoNextPage_Click(object sender, RoutedEventArgs e)
        {
            bindingWebBrowser.GoForward();
        }

        void GoHomePage_Click(object sender, RoutedEventArgs e)
        {
            bindingWebBrowser.GoHome();
        }
        WebBrowserUserControl bindingWebBrowser;

        /// <summary>
        /// 控制面板绑定的浏览器
        /// </summary>
        public WebBrowserUserControl BindingWebBrowser
        {
            get { return bindingWebBrowser; }
            set 
            { 
                bindingWebBrowser = value;
                bindingWebBrowser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(bindingWebBrowser_DocumentCompleted);
            }
        }

        void bindingWebBrowser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            this.GoPreviousPage.IsEnabled = bindingWebBrowser.CanGoBack;
            this.GoNextPage.IsEnabled = bindingWebBrowser.CanGoForward;
        } 

	}
}